﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;
using System.Data;

namespace jmwqz
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Maticsoft.Model.admindata model = GetAdminInfo();
            //if (model == null)
            //{
            //    Response.Redirect("login.aspx");
            //    return;
            //}
        }

        /// <summary>
        /// 取得管理员信息
        /// </summary>
        public Maticsoft.Model.admindata GetAdminInfo()
        {
            if (IsAdminLogin())
            {
                Maticsoft.Model.admindata model = Session[MXKeys.SESSION_ADMIN_INFO] as Maticsoft.Model.admindata;
                if (model != null)
                {
                    return model;
                }
            }
            return null;
        }

        public bool IsAdminLogin()
        {
            //如果Session为Null
            if (Session[MXKeys.SESSION_ADMIN_INFO] != null)
            {
                return true;
            }
            else
            {
                //检查Cookies
                string adminname = Utils.GetCookie("AdminName", "MxWeiXinPF");
                string adminpwd = Utils.GetCookie("AdminPwd", "MxWeiXinPF");
                if (adminname != "" && adminpwd != "")
                {
                    Maticsoft.BLL.admindata data = new Maticsoft.BLL.admindata();
                    DataSet ds = data.GetList("username='" + adminname + "' and password='" + adminpwd + "'");
                    if (!Maticsoft.Common.Util2.CheckDataSet(ds))
                    {
                        return false;
                    }
                    List<Maticsoft.Model.admindata> datas = data.DataTableToList(ds.Tables[0]);
                    if (datas == null || datas.Count != 1)
                    {
                        return false;
                    }
                    Maticsoft.Model.admindata model = datas[0];
                    if (model != null)
                    {
                        Session[MXKeys.SESSION_ADMIN_INFO] = model;
                        return true;
                    }
                }
            }
            return false;
        }
    }
}